package com.cskaoyan.service.auth.wxuser;

import com.cskaoyan.bean.MallUser;
import com.cskaoyan.bean.MallUserExample;
import com.cskaoyan.mapper.MallUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @program: project-market
 * @description: 用户登录登出业务实现类
 * @author: Jesson Guo
 * @create: 2021-12-02 19:50
 **/
@Service
public class WxAuthServiceImpl implements WxAuthService {
    @Autowired
    MallUserMapper userMapper;
    //用户登录
    @Override
    public MallUser wxAuthLogin(MallUser wxUserLoginBO) {
        MallUserExample userExample = new MallUserExample();
        MallUserExample.Criteria userExampleCriteria = userExample.createCriteria();
        //判不删
        userExampleCriteria.andDeletedEqualTo(false);
        userExampleCriteria.andUsernameEqualTo(wxUserLoginBO.getUsername());
        List<MallUser> mallUsers = userMapper.selectByExample(userExample);
        for (MallUser user : mallUsers) {
            if (user.getPassword().equals(wxUserLoginBO.getPassword())){
                wxUserLoginBO.setId(user.getId());
                wxUserLoginBO.setLastLoginTime(new Date());
                wxUserLoginBO.setNickname(user.getNickname());
                userMapper.updateByPrimaryKeySelective(wxUserLoginBO);
                return wxUserLoginBO;
            }
        }
        return null;
    }
}
